package com.emergency.examine.controller;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.examine.dao.QuestionDao;
import com.emergency.examine.domain.Exam;
import com.emergency.examine.domain.Question;
import com.emergency.examine.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/question")
@Api(value = "试题类", tags = "记录试题信息")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @ApiOperation(value = "题目接口", notes = "保存题目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "题目名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "题目类型", required = true, paramType = "query", dataType = "ExamType"),
            @ApiImplicitParam(name = "score", value = "分值", required = true, paramType = "query", dataType = "Double"),
            @ApiImplicitParam(name = "diff", value = "难度", required = true, paramType = "query", dataType = "ExamDiff"),
            @ApiImplicitParam(name = "answer", value = "答案", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public Result save(@RequestBody Question question) {
        String id = questionService.save(question);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    @ApiOperation(value = "题目查询接口", notes = "查询题目信息")
    @RequestMapping(value = "get/{questionId}", method = RequestMethod.GET)
    public Result get(@PathVariable("questionId") Long questionId) {
        Question question = questionService.getInfo(questionId);
        return new Result(true, StatusCode.OK, "操作成功", question);
    }

    @ApiOperation(value = "题目列表获取接口", notes = "题目列表")
    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<Question> pageList = questionService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }

    @ApiOperation(value = "删除考试信息接口", notes = "删除考试信息")
    @RequestMapping(value = "del/{questionId}", method = RequestMethod.POST)
    public Result del(@PathVariable("questionId") Long questionId) {
        questionService.del(questionId);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
